function slide(type){
  var active = $('.item.active')
      , pos = $('.item.active').index()
      , direction = type == 'next' ? 'left' : 'right'
      , fallback  = type == 'next' ? 'first' : 'last'
      , diff = type == 'next' ? 1 : -1

  var next = (pos + diff < 0 || pos + diff >= $('.item').length) ? $('.item')[fallback](): $('.item').eq(pos+diff);
  console.log(next);

  next.addClass(type);
  next[0].offsetWidth; //force reflow
  active.addClass(direction)
  next.addClass(direction);

  $(window).bind('animationend webkitAnimationEnd MSAnimationEnd', function() {
    console.log('ended');
    next.removeClass([type, direction].join(' ')).addClass('active')
    active.removeClass(['active', direction].join(' '))
    next.unbind();
  })
}